package com.gl.glcourses.services.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gl.glcourses.repository.ICursosRepository;
import com.gl.glcourses.repository.ITipoRecursoRepository;
import com.gl.glcourses.services.ITipoRecursoServices;
import com.gl.glcourses.vos.Confirmacion;
import com.gl.glcourses.vos.TipoRecurso;
import com.gl.glcourses.vos.constants.Constants;

@Service
@RemotingDestination(channels = { "my-amf" })
@Transactional
public class TipoRecursoServices implements ITipoRecursoServices {
	@Autowired
	ITipoRecursoRepository<TipoRecurso> repotporec;
	 
	@Autowired
	ICursosRepository<TipoRecurso> repocurso;
	
	protected final Log logger = LogFactory.getLog(getClass());
	

	@Transactional
	@Override
	public Confirmacion agregarTpoRec(TipoRecurso tipo) throws Exception {
	Confirmacion confirmacion = new Confirmacion();

	if (repotporec.findTipoRecurso("nombre",tipo.getNombre())==null){
		repocurso.save(tipo);
	}
	confirmacion.setEstado(Constants.CONFIRMACION_OK);
	return confirmacion;
}

/* Traemos el listado Tipos de Recurso */
//@Cachea(cacheKey="categorias", expireTime=0)
public List<TipoRecurso> listarTpoRec() {
	logger.info("getTipoRecList");
	try {
		return repotporec.getListEntity(TipoRecurso.class);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
public TipoRecurso buscarTpoRecurso(String string){
    TipoRecurso tporecurso;
    tporecurso= (TipoRecurso) repotporec.findTipoRecurso("nombre", string);
return tporecurso;
}
}